var config = require('../../../config/config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    action: "brains",
    bill_list:[],
    record_list:[]
  },
  dingshui:function(){
   wx.redirectTo({
     url: '../../takeWater/takeWater-index/takeWater-index',
   })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  //水票列表
  getTicketUrl:function(e){
    var that = this;
    var member_info = (wx.getStorageSync('member_info'));
    wx.request({
      url: config.member_bill_list,
      data: {
        mid: member_info.mid,
        aid: member_info.aid,
        sid: member_info.sid,
      },
      method: 'GET',
      success: function (res) {
        that.setData({
          bill_list: res.data.data.bill_list
        })
      },
      fail: function () {
      },
    })
  },
  // 水票明细
  getDetailUrl: function (e) {
    var that = this;
    var member_info = (wx.getStorageSync('member_info'));
    wx.request({
      url: config.member_bill_record  ,
      data: {
        mid: member_info.mid,
        aid: member_info.aid,
        sid: member_info.sid,
      },
      method: 'GET',
      success: function (res) {
        that.setData({
          record_list: res.data.data.record_list.data
        })
      },
      fail: function () {
      },
    })
  },

  onLoad: function (options) {
    var member_info = (wx.getStorageSync('member_info'));
    this.setData({
      mid: member_info.mid,
    })
    this.getTicketUrl();
  },
  onshow() {
    const self = this;
    let { action } = self.options
    action = action || 'brains'
    self.data.action = action
    self.setData(self.data)
  },
  toggleTabs(e) {
    const self = this;
    const { action } = e.currentTarget.dataset
    switch (action) {
      case 'brains': self.showBrains(); break;
      case 'stamina': self.showStamina(); break;
      default: break;
    }
  },
  showBrains() {
    const self = this;
    self.options.action = "brains"
    self.onshow()
  },
  showStamina() {
    const self = this;
    self.options.action = "stamina"
    self.onshow();
    if (this.data.record_list.length){
      return
    }
    this.getDetailUrl()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})